﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Housing;

public partial class GovDepartment_GovernCheck : System.Web.UI.Page
{
    Apply apply=new Apply();
    protected void Page_Load(object sender, EventArgs e)
    {
        string totleincome = "0";
        string avgincome = "0";
        float monthincome = 0;
        SqlDataReader dr= apply.GetApplyForCheckByNoid(Request.QueryString["id"].ToString());
        if (dr.Read())
        {
            avgincome = dr["apply_avgincome"].ToString();
            totleincome = dr["apply_yearincome"].ToString();
            monthincome = float.Parse(avgincome) / 12;
            lblnoid.Text = dr["apply_noid"].ToString();
        }
        Documents document = new Documents();
        string doctype = document.GetDocTypeByNoid(lblnoid.Text);
        if (ckblowest.Text == doctype)
            ckblowest.Checked = true;
        else if (ckblow.Text == doctype)
        {
            ckblow.Checked = true;
            txbincome.Text = totleincome.ToString();
            txbavgincome.Text = avgincome.ToString();
        }
        else if (ckbother.Text == doctype)
        {
            ckbother.Checked = true;
            txbincome1.Text = totleincome.ToString();
            txbmonthincome.Text = monthincome.ToString("0.00");
        }
        else
            return;
    }
    protected void btnunpass_Click(object sender, EventArgs e)
    {
        bool fail = apply.SetApplyUnPass(lblnoid.Text);
        if (fail)
            WebHelper.AlertAndCloseThenRefreshLastPage("该申请单已被否决！");
        else
            WebHelper.Alert("否决不通过，请重新操作");
    }
    protected void btnpass_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txbdate.Text))
        {
            GovernmentCheck governmentcheck = new GovernmentCheck();
            bool succAddGovCheck=governmentcheck.AddGovCheck(lblnoid.Text, txbname.Text, txbreponsname.Text, txbdate.Text);
            if (succAddGovCheck)
            {
                bool succAddOne = apply.SetCheckStateAddOne(lblnoid.Text);
                if (succAddOne)
                    WebHelper.AlertAndCloseThenRefreshLastPage("审核成功，请继续其他操作！");
                else
                    WebHelper.Alert("审核失败，请重新操作");
            }
            else
                WebHelper.Alert("已审核或审核失败！");
        }
        else
            WebHelper.Alert("请填写审核日期");
    }
}
